$(function () {


  var currentPage = 1;
  var pageSize = 5;

    function render() {
        $.ajax({
            type: 'get',
            url: '/user/queryUser',
            data: {
             page: currentPage ,
             pageSize : pageSize
            },
            dataType: 'json',
            success: function (res) {
                console.log(res);
                $('tbody').html(template('tmp',res))
            // $('tbody').html(template('tmp',res))

            setPage(res.total);
            }
        })
    }
    render();


var id = null;
var isDelete = null;
$('tbody').on('click', '.btn', function(){
   id = $(this).parent().attr('data-id');
   isDelete = $(this).hasClass('btn-danger') ? 0 : 1 ;
   console.log(id,isDelete);
   
})
$('.btn-ok').click(function(){

    	$.ajax({
            type: 'post',
            url: '/user/updateUser',
            data: {
                id : id ,
                isDelete : isDelete

            },
            dataType: 'json',
            success: function (res) {
                    console.log(res);

                   render();
                   $('.modal-user').modal('hide'); 
            }
        })
})


function setPage (total){

    $("#paginator").bootstrapPaginator({
        bootstrapMajorVersion:3,//默认是2，如果是bootstrap3版本，这个参数必填
        currentPage: currentPage,//当前页
        totalPages:Math.ceil(total / pageSize) ,//总页数
        size:"small",//设置控件的大小，mini, small, normal,large
        onPageClicked:function(event, originalEvent, type,page){
          //为按钮绑定点击事件 page:当前点击的按钮值

          currentPage = page;

          render();
        }
  });
   
}
    
})